package com.gliese.mp3;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

import com.gliese.mp3.module.Mp3;
import com.gliese.util.file.FileReaderHelper;

/**
 * Hello world!
 * 
 */
public class App {
	public static void main(String[] args) throws IOException {
		System.out
				.println("=================start unencode mp3==================");
		InputStream inputStream = null;
		try {
			inputStream = FileReaderHelper.readResourceByURL("/preview1.mp3");
		} catch (IOException e) {
			System.out.println("InputStream is null !");
		}
		long offset = inputStream.available() - 128;
		long skipResultNum = inputStream.skip(offset);
		assert skipResultNum != offset : "error of skip() occurs";
		byte[] mp3Tag = new byte[128];
		inputStream.read(mp3Tag);
		String title = new String(mp3Tag, 3, 30,Charset.forName("GBK"));
		// System.out.println(title);
		String artist = new String(mp3Tag, 33, 30);
		String album = new String(mp3Tag, 63, 30);
		String year = new String(mp3Tag, 93, 4);
		String comment = new String(mp3Tag, 97, 30, Charset.forName("GBK"));
		int genre = mp3Tag[127];
		Mp3 mp3 = new Mp3(title, artist, album, year, comment, genre);
		System.out.println(mp3);
	}
}
